package com.example.Extension.BeanDefinitionRegistryPostProcessor;

import com.example.LifeCycle.commons.Car;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @Description TODO
 * @Date 2024/6/3 0:39
 * @Created by houjunfeng
 */
@Component
public class MyBean implements BeanDefinitionRegistryPostProcessor {
    @Override
    public  void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException{
        System.out.println("postProcessBeanDefinitionRegistry的bean数量:................."+beanDefinitionRegistry.getBeanDefinitionCount());
        //RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(Car.class);这个和下面可以通用，效果一样
        AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(Car.class).getBeanDefinition();
        beanDefinitionRegistry.registerBeanDefinition("Defination",beanDefinition);
        System.out.println(Arrays.asList(beanDefinitionRegistry.getBeanDefinitionNames()));
    };
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException{
        System.out.println("postProcessBeanFactory的bean数量:................."+beanFactory.getBeanDefinitionCount());
        System.out.println(Arrays.asList(beanFactory.getBeanDefinitionNames()));
    };
}
